package com.netx.generics.io;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

import com.netx.generics.basic.Checker;


public class BufferedWriter extends java.io.BufferedWriter {

	public BufferedWriter(OutputStream out) {
		super(new OutputStreamWriter((OutputStream)Checker.checkNull(out, "out")));
	}

	public BufferedWriter(OutputStream out, int bufferSize) {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out")
		), (int)Checker.checkMinValue(bufferSize, 1, "bufferSize"));
	}

	public BufferedWriter(OutputStream out, Charset cs) {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out"),
			(Charset)Checker.checkNull(cs, "cs")
		));
	}

	public BufferedWriter(OutputStream out, Charset cs, int bufferSize) {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out"),
			(Charset)Checker.checkNull(cs, "cs")
		), (int)Checker.checkMinValue(bufferSize, 1, "bufferSize"));
	}

	public BufferedWriter(OutputStream out, CharsetEncoder enc) {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out"),
			(CharsetEncoder)Checker.checkNull(enc, "enc")
		));
	}

	public BufferedWriter(OutputStream out, CharsetEncoder enc, int bufferSize) {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out"),
			(CharsetEncoder)Checker.checkNull(enc, "enc")
		), (int)Checker.checkMinValue(bufferSize, 1, "bufferSize"));
	}

	public BufferedWriter(OutputStream out, String charsetName) throws UnsupportedEncodingException {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out"),
			(String)Checker.checkEmpty(charsetName, "charsetName")
		));
	}

	public BufferedWriter(OutputStream out, String charsetName, int bufferSize) throws UnsupportedEncodingException {
		super(new OutputStreamWriter(
			(OutputStream)Checker.checkNull(out, "out"),
			(String)Checker.checkEmpty(charsetName, "charsetName")
		), (int)Checker.checkMinValue(bufferSize, 1, "bufferSize"));
	}
	
	public BufferedWriter(Writer writer) {
		super((Writer)Checker.checkNull(writer, "writer"));
	}

	public BufferedWriter(Writer writer, int bufferSize) {
		super(
			(Writer)Checker.checkNull(writer, "writer"),
			(int)Checker.checkMinValue(bufferSize, 1, "bufferSize")
		);
	}
}
